public class Test250902 {
    //重写equals
    public static void main(String[] args) {
        Employee employee1 = new Employee("张三",20);
        Employee employee2 = new Employee("李四", 20);

        System.out.println(employee1.equals(employee2));
    }

    //接口
    public static void main2(String[] args) {
        Duck duck = new Duck();
        duck.fly();
        duck.swim();
    }

    //静态成员被所有对象共享
    public static void main1(String[] args) {
        //这里是实例化后未正常使用
        Student s1 = new Student();
        Student s2 = new Student();

        Student.school = "阳光小学";

        System.out.println(s1.school);

        Student.school = "希望小学";

        //这里建议以类名调用
        System.out.println(s2.school);
    }
}

//静态成员被所有对象共享
class Student {
    static String school;
}

//接口
interface Flyable {
    //接口方法：只声明，不实现
    void fly();//暗含 public abstract
}

interface Swimmable {
    void swim();
}

class Duck implements Flyable, Swimmable {
    @Override
    public void fly() {
        System.out.println("鸭子会飞");
    }

    @Override
    public void swim() {
        System.out.println("鸭子游泳");
    }
    //必须重写接口中的所有方法
}

//重写equals
class Employee {
    String name;
    int age;

    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object obj) {
        //这里因为向上转型，属于它或它的子类
        //若，则转为Employee且记为other
        if (obj instanceof Employee other) {
            //这里equals是Objects中的字符串比较，后者比较地址
            return name.equals(other.name) && age == other.age;
        }
        return false;
    }
}